{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/stu_15527388015/.local/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:526: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n",
      "  _np_qint8 = np.dtype([(\"qint8\", np.int8, 1)])\n",
      "/home/stu_15527388015/.local/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:527: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n",
      "  _np_quint8 = np.dtype([(\"quint8\", np.uint8, 1)])\n",
      "/home/stu_15527388015/.local/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:528: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n",
      "  _np_qint16 = np.dtype([(\"qint16\", np.int16, 1)])\n",
      "/home/stu_15527388015/.local/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:529: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n",
      "  _np_quint16 = np.dtype([(\"quint16\", np.uint16, 1)])\n",
      "/home/stu_15527388015/.local/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:530: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n",
      "  _np_qint32 = np.dtype([(\"qint32\", np.int32, 1)])\n",
      "/home/stu_15527388015/.local/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:535: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n",
      "  np_resource = np.dtype([(\"resource\", np.ubyte, 1)])\n"
     ]
    }
   ],
   "source": [
    "import tensorflow as tf#这里的tensorflow的版本是1.13.1\n",
    "from tensorflow.examples.tutorials.mnist import input_data#导入minist数据集所在的包\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "import time\n",
    "import random\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 1导入数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "WARNING:tensorflow:From <ipython-input-2-6795a4af02e5>:2: read_data_sets (from tensorflow.contrib.learn.python.learn.datasets.mnist) is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "Please use alternatives such as official/mnist/dataset.py from tensorflow/models.\n",
      "WARNING:tensorflow:From /home/stu_15527388015/.local/lib/python3.7/site-packages/tensorflow/contrib/learn/python/learn/datasets/mnist.py:260: maybe_download (from tensorflow.contrib.learn.python.learn.datasets.base) is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "Please write your own downloading logic.\n",
      "WARNING:tensorflow:From /home/stu_15527388015/.local/lib/python3.7/site-packages/tensorflow/contrib/learn/python/learn/datasets/mnist.py:262: extract_images (from tensorflow.contrib.learn.python.learn.datasets.mnist) is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "Please use tf.data to implement this functionality.\n",
      "Extracting ./mnist_data/train-images-idx3-ubyte.gz\n",
      "WARNING:tensorflow:From /home/stu_15527388015/.local/lib/python3.7/site-packages/tensorflow/contrib/learn/python/learn/datasets/mnist.py:267: extract_labels (from tensorflow.contrib.learn.python.learn.datasets.mnist) is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "Please use tf.data to implement this functionality.\n",
      "Extracting ./mnist_data/train-labels-idx1-ubyte.gz\n",
      "WARNING:tensorflow:From /home/stu_15527388015/.local/lib/python3.7/site-packages/tensorflow/contrib/learn/python/learn/datasets/mnist.py:110: dense_to_one_hot (from tensorflow.contrib.learn.python.learn.datasets.mnist) is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "Please use tf.one_hot on tensors.\n",
      "Extracting ./mnist_data/t10k-images-idx3-ubyte.gz\n",
      "Extracting ./mnist_data/t10k-labels-idx1-ubyte.gz\n",
      "WARNING:tensorflow:From /home/stu_15527388015/.local/lib/python3.7/site-packages/tensorflow/contrib/learn/python/learn/datasets/mnist.py:290: DataSet.__init__ (from tensorflow.contrib.learn.python.learn.datasets.mnist) is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "Please use alternatives such as official/mnist/dataset.py from tensorflow/models.\n"
     ]
    }
   ],
   "source": [
    "#1准备数据，one_hot=true表示目标值用one-hot编码的形式去表达\n",
    "minist=input_data.read_data_sets(\"./mnist_data\",one_hot=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 2数据探索"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Datasets(train=<tensorflow.contrib.learn.python.learn.datasets.mnist.DataSet object at 0x7f0d1e557310>, validation=<tensorflow.contrib.learn.python.learn.datasets.mnist.DataSet object at 0x7f0d644f1cd0>, test=<tensorflow.contrib.learn.python.learn.datasets.mnist.DataSet object at 0x7f0d644f1a50>) <class 'tensorflow.contrib.learn.python.learn.datasets.base.Datasets'>\n"
     ]
    }
   ],
   "source": [
    "print(minist,type(minist))#看一下mnist及其数据类型"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "训练集： <tensorflow.contrib.learn.python.learn.datasets.mnist.DataSet object at 0x7f0d1e557310>\n",
      "训练集的数据类型: <class 'tensorflow.contrib.learn.python.learn.datasets.mnist.DataSet'>\n"
     ]
    }
   ],
   "source": [
    "#训练集\n",
    "print(\"训练集：\",minist.train)\n",
    "print(\"训练集的数据类型:\",type(minist.train))#这里看一下mnist之中train的数据类型 我们这里需要的是mnist之中train中的images和labels"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "训练集minist.train中的images：\n",
      " [[0. 0. 0. ... 0. 0. 0.]\n",
      " [0. 0. 0. ... 0. 0. 0.]\n",
      " [0. 0. 0. ... 0. 0. 0.]\n",
      " ...\n",
      " [0. 0. 0. ... 0. 0. 0.]\n",
      " [0. 0. 0. ... 0. 0. 0.]\n",
      " [0. 0. 0. ... 0. 0. 0.]]\n",
      "训练集minist.train中的images数据类型: <class 'numpy.ndarray'>\n",
      "训练集minist.train中的images的数据维度： (55000, 784)\n"
     ]
    }
   ],
   "source": [
    "print(\"训练集minist.train中的images：\\n\",minist.train.images)\n",
    "print(\"训练集minist.train中的images数据类型:\",type(minist.train.images))#既然是ndarray类型 那就看看数据的维度吧\n",
    "print(\"训练集minist.train中的images的数据维度：\",minist.train.images.shape)\n",
    "#minist.train.images是(55000, 784)的二维数组  ；minist.train.labels是(55000, 10)的二维数组"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "训练集minist.train中的labels：\n",
      " [[0. 0. 0. ... 1. 0. 0.]\n",
      " [0. 0. 0. ... 0. 0. 0.]\n",
      " [0. 0. 0. ... 0. 0. 0.]\n",
      " ...\n",
      " [0. 0. 0. ... 0. 0. 0.]\n",
      " [0. 0. 0. ... 0. 0. 0.]\n",
      " [0. 0. 0. ... 0. 1. 0.]]\n",
      "训练集minist.train中的labels数据类型: <class 'numpy.ndarray'>\n",
      "训练集minist.train中的labels的数据维度： (55000, 10)\n"
     ]
    }
   ],
   "source": [
    "print(\"训练集minist.train中的labels：\\n\",minist.train.labels)\n",
    "print(\"训练集minist.train中的labels数据类型:\",type(minist.train.labels))#既然是ndarray类型 那就看看数据的维度吧\n",
    "print(\"训练集minist.train中的labels的数据维度：\",minist.train.labels.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "在images中的元素索引: 1 \n",
      "labels本身的值： [0. 0. 0. 1. 0. 0. 0. 0. 0. 0.] \n",
      "对应代表的数字: 3\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAPsAAAD4CAYAAAAq5pAIAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/Il7ecAAAACXBIWXMAAAsTAAALEwEAmpwYAAAO+ElEQVR4nO3df5BV9XnH8c/juiwRAgKmFJHEX9AGZYJ1g22kiQ1NomQMpqlG2nHoDM2ajHbMTKajtZ0RJzMNsYk20xqTNVBJxhozSRypMVGKTJlEiywG+eHagAwU1oXVMAmQWGTZp3/sMbPRPd+z3HN/7T7v18zOvfc89+x55sJnz733e7/3a+4uAGPfaY1uAEB9EHYgCMIOBEHYgSAIOxDE6fU82Dhr8/GaUM9DAqH8n36l1/24DVcrFXYzu1LSVyS1SPqGu69M3X+8JugyW1TmkAASNvn63FrFT+PNrEXSvZKukjRX0lIzm1vp7wNQW2Vesy+QtNvd97j765K+LWlJddoCUG1lwj5T0v4htw9k236LmXWYWZeZdZ3Q8RKHA1BGzd+Nd/dOd2939/ZWtdX6cABylAl7j6RZQ26fk20D0ITKhH2zpNlmdp6ZjZN0vaS11WkLQLVVPPTm7v1mdrOkJzQ49Lba3XdWrTMAVVVqnN3dH5f0eJV6AVBDfFwWCIKwA0EQdiAIwg4EQdiBIAg7EARhB4Ig7EAQhB0IgrADQRB2IAjCDgRB2IEgCDsQBGEHgiDsQBCEHQiCsANBEHYgCMIOBEHYgSAIOxAEYQeCIOxAEIQdCIKwA0EQdiAIwg4EQdiBIEqt4orRr2XunGT9xc9MSd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B5y+jpf0vPZz85G9ybpIQ0+rTuhwfc2lkuaJmm9pF2S/lPS1Cbq7VuStkvapsFgzWhQbws1+BR9m6St2c/iRj92ib7q8rjxcVkgCN6gA4Ig7EAQhB0IgrADQRB2IAjCDgRB2IEg/h+E0IVyeLad3wAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "def show_image(i):\n",
    "    \"\"\"写一个函数，这里可以把mnist中的train中的一个images和它对应的lable显示出来\"\"\"\n",
    "    temp=minist.train.images[i]#获取mnist中images的第i个数据 此时是一个1x784的数组\n",
    "    temp=temp.reshape(28,28)#然后把它转成28x28的二维数据，目的是放入plt.imshow()中可视化出来\n",
    "    plt.imshow(temp)\n",
    "    print(\"在images中的元素索引:\",i,\"\\nlabels本身的值：\",minist.train.labels[i],\"\\n对应代表的数字:\",np.argmax(minist.train.labels[i]))\n",
    "show_image(1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "在images中的元素索引: 43070 \n",
      "labels本身的值： [0. 0. 1. 0. 0. 0. 0. 0. 0. 0.] \n",
      "对应代表的数字: 2\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAPsAAAD4CAYAAAAq5pAIAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/Il7ecAAAACXBIWXMAAAsTAAALEwEAmpwYAAANlklEQVR4nO3df6zV9X3H8dcLvILS1kCht1dKrVrU2a1Dc4fdqp3WtFLaBf3HSKxhKek1S23axD/q3LLSfzbTTrsmXdxQSLFjmi7qvDVkKyVdTO3GuDCKCFOcQYUg0NIM7Co/3/vjfjFXvedz7j2/8f18JDfnnO/7fM/3na+8/P463/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clPSNpm0aDNdCl3q7W6C76Nklbq7/F3V53hb46st74uiyQBCfogCQIO5AEYQeSIOxAEoQdSIKwA0kQdiCJ/wcP3uyYKc05nQAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "#从image的0-55000中随机的抽取个数据 然后显示一下\n",
    "show_image(random.randint(0,minist.train.images.shape[0]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "在images中的元素索引: 50909 \n",
      "labels本身的值： [0. 0. 0. 0. 0. 1. 0. 0. 0. 0.] \n",
      "对应代表的数字: 5\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAPsAAAD4CAYAAAAq5pAIAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/Il7ecAAAACXBIWXMAAAsTAAALEwEAmpwYAAAOI0lEQVR4nO3dbYwd5XnG8euyWeNiILGBGGNMoMSguhU1dGVTGSooCQG31ESNKEgNboS6aQtSUvEBSiqB1A9FKSFq1SSqCW7cNoAiXgpqUYrrUCFo4npNXL/gBFPHDnaMXWoINuDXvfthh2gNe55dnzlv9v3/SatzztxnZm6NfHnmzMw5jyNCAI5/E7rdAIDOIOxAEoQdSIKwA0kQdiCJEzq5skk+MSZrSidXCaSyT2/rQOz3aLVaYbd9jaS/ljRR0jci4t7S+ydriub7qjqrBFCwMlY0rDV9GG97oqSvSrpW0hxJN9me0+zyALRXnc/s8yS9EhGbI+KApEckLWpNWwBarU7YZ0p6dcTrbdW0I9gesD1oe/Cg9tdYHYA62n42PiKWRER/RPT36cR2rw5AA3XCvl3SrBGvz66mAehBdcK+StJs2+fZniTpRklPtaYtAK3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AEoQdSIKwA0kQdiAJwg4k8f9pnD56F34oCAAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "#从image的0-55000中随机的抽取个数据 然后显示一下\n",
    "show_image(random.randint(0,minist.train.images.shape[0]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "在images中的元素索引: 4901 \n",
      "labels本身的值： [0. 0. 0. 0. 0. 0. 0. 1. 0. 0.] \n",
      "对应代表的数字: 7\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAPsAAAD4CAYAAAAq5pAIAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/Il7ecAAAACXBIWXMAAAsTAAALEwEAmpwYAAAOGUlEQVR4nO3de7BdZXnH8d8vySEZLqnEaCaGVORSLrYQ9TQ4mEEs6ABTByiWmmlp6qDHjsTCFIdS7FT+ctIWYdCmtOFSgsNlHJWSP6KVplpqZTIkkEJCDGAmCCEk0jhcBHJ9+sdZcY5w9rsPe619Mc/3M3Nm77Oevfb7ZE9+Z629373364gQgIPfpH43AKA3CDuQBGEHkiDsQBKEHUhiSi8HO8RTY5oO6+WQQCqv6xfaHbs8Xq1W2G2fI+lGSZMl3RIRS0q3n6bDdJrPqjMkgILVsaplrePTeNuTJS2VdK6kkyUttH1yp/cHoLvqPGefL+mpiNgcEbsl3SPp/GbaAtC0OmGfI+mZMb8/W237FbZHbK+xvWaPdtUYDkAdXX81PiKWRcRwRAwPaWq3hwPQQp2wb5U0d8zvR1XbAAygOmF/SNLxtt9j+xBJn5S0opm2ADSt46m3iNhre7Gkf9fo1NttEbGhsc4ANKrWPHtErJS0sqFeAHQRb5cFkiD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m0mSucIAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "#从image的0-55000中随机的抽取个数据 然后显示一下\n",
    "show_image(random.randint(0,minist.train.images.shape[0]))#这里随机抽取了3个 图片和标签大致是对的上的"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 3搭建网络"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "#训练集特征，虽然知道是55000行，784列，先不写上,这里用tensorflow里面的placeholder先占位，在session开始run的时候再填充\n",
    "# 同理训练集特征，虽然知道是55000行，784列\n",
    "x=tf.placeholder(dtype=tf.float32,shape=(None,784))\n",
    "y_true=tf.placeholder(dtype=tf.float32,shape=(None,10))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "WARNING:tensorflow:From /home/stu_15527388015/.local/lib/python3.7/site-packages/tensorflow/python/framework/op_def_library.py:263: colocate_with (from tensorflow.python.framework.ops) is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "Colocations handled automatically by placer.\n"
     ]
    }
   ],
   "source": [
    "#2构建模型\n",
    "#w和b用变量存储，w维度是[784,10],b=[1,10]才对啊，只有一维，[10]也可以表示  \n",
    "weight=tf.Variable(initial_value=tf.random_normal(shape=[784,10]))#这里的w和b先随机生成\n",
    "bias=tf.Variable(initial_value=tf.random_normal(shape=[10]))\n",
    "#权重和偏置就定义好了,预测值就可以写出来了\n",
    "y_predict=tf.matmul(x,weight)+bias# x(None,784)*w(784,10)=(None,10)  \n",
    "#然后(None,10)+b(1,10) 按说矩阵相加应该完全维度一致才对  这里直接是把b直接加到w*weight相乘之后的列上面去"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "WARNING:tensorflow:From <ipython-input-13-6725d49d354d>:4: softmax_cross_entropy_with_logits (from tensorflow.python.ops.nn_ops) is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "\n",
      "Future major versions of TensorFlow will allow gradients to flow\n",
      "into the labels input on backprop by default.\n",
      "\n",
      "See `tf.nn.softmax_cross_entropy_with_logits_v2`.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "#3构建损失函数  \n",
    "# tf.nn.softmax_cross_entropy_with_logits(labels=y_true,logits=y_predict) 这句代码返回的是计算交叉熵损失 返回一个列表\n",
    "# 55000个样本 如果 y_true=y_predict 返回1   这里是55000个0、1组成的列表  所以求这个列表的平均值就是准确率\n",
    "#labels上文用one-hot表示  这里传进入这里 也是one-hot的格式\n",
    "error=tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(labels=y_true,logits=y_predict))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "#4优化损失\n",
    "optimizer=tf.train.GradientDescentOptimizer(learning_rate=0.9).minimize(error)#采用梯度下降法 学习率0.75 去优化上面准备好的 损失函数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "#准确率计算\n",
    "equal_list=tf.equal(tf.argmax(y_true,1),tf.argmax(y_predict,1))#真实值与预测值最大的概率的位置的索引是否相等，返回一个list list中是布尔值\n",
    "#argmax(y_true,1)中的1表示 按照列求最大值\n",
    "accuracy=tf.reduce_mean(tf.cast(equal_list,tf.float32))#把布尔值True和False转换成1和0 然后求一下均值 就是准确率"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 4训练模型以及输出准确率"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "训练之前，损失为：13.849242210388184\n",
      "第0次训练的损失为13.849242210388184,准确率为:0.13567273318767548\n",
      "第100次训练的损失为0.99223393201828,准确率为:0.796818196773529\n",
      "第200次训练的损失为0.7658810615539551,准确率为:0.8375818133354187\n",
      "第300次训练的损失为0.6643883585929871,准确率为:0.8535090684890747\n",
      "第400次训练的损失为0.6022462844848633,准确率为:0.8640545606613159\n",
      "第500次训练的损失为0.5589942336082458,准确率为:0.8706545233726501\n",
      "第600次训练的损失为0.526560366153717,准确率为:0.8759636282920837\n",
      "第700次训练的损失为0.5010025501251221,准确率为:0.880581796169281\n",
      "第800次训练的损失为0.4801298677921295,准确率为:0.884181797504425\n",
      "第900次训练的损失为0.4626203179359436,准确率为:0.8876545429229736\n",
      "第1000次训练的损失为0.44763046503067017,准确率为:0.8903999924659729\n",
      "第1100次训练的损失为0.4345952272415161,准确率为:0.8925091028213501\n",
      "第1200次训练的损失为0.4231193959712982,准确率为:0.8947636485099792\n",
      "第1300次训练的损失为0.41291555762290955,准确率为:0.8967090845108032\n",
      "第1400次训练的损失为0.40376797318458557,准确率为:0.8983091115951538\n",
      "第1500次训练的损失为0.3955100178718567,准确率为:0.8995636105537415\n",
      "第1600次训练的损失为0.38800978660583496,准确率为:0.9011090993881226\n",
      "第1700次训练的损失为0.3811614215373993,准确率为:0.9023454785346985\n",
      "第1800次训练的损失为0.3748783469200134,准确率为:0.9038909077644348\n",
      "第1900次训练的损失为0.3690893352031708,准确率为:0.9049999713897705\n",
      "第2000次训练的损失为0.36373481154441833,准确率为:0.9061636328697205\n",
      "第2100次训练的损失为0.35876473784446716,准确率为:0.9072181582450867\n",
      "第2200次训练的损失为0.35413679480552673,准确率为:0.9081454277038574\n",
      "第2300次训练的损失为0.349814772605896,准确率为:0.9089636206626892\n",
      "第2400次训练的损失为0.34576767683029175,准确率为:0.9098727107048035\n",
      "第2500次训练的损失为0.34196874499320984,准确率为:0.9104909300804138\n",
      "第2600次训练的损失为0.3383946716785431,准确率为:0.9113090634346008\n",
      "第2700次训练的损失为0.3350251317024231,准确率为:0.9121817946434021\n",
      "第2800次训练的损失为0.331842303276062,准确率为:0.9129636287689209\n",
      "第2900次训练的损失为0.32883039116859436,准确率为:0.9138908982276917\n",
      "第3000次训练的损失为0.3259754478931427,准确率为:0.914509117603302\n",
      "最终训练出来的w:\n",
      "[[ 0.06829474 -0.58562446  0.13977459 ... -1.0120397   0.5823616\n",
      "  -0.34395593]\n",
      " [-0.18016808 -0.16406116 -0.9776032  ...  1.1943406   0.24999997\n",
      "   0.25775212]\n",
      " [ 0.8174994   0.5268698   1.1381471  ... -0.2287585   0.61120784\n",
      "   0.25902218]\n",
      " ...\n",
      " [ 1.0418726   0.5006273   1.6359488  ... -0.03812838 -2.1475058\n",
      "  -0.03138096]\n",
      " [ 1.6830376   1.6247953   0.7387957  ... -0.9631998   0.4334884\n",
      "   1.1034408 ]\n",
      " [ 1.2097656  -1.1120801   0.14490807 ...  0.8858248   0.65909535\n",
      "  -0.65722114]]\n",
      "b:[-2.0099409   0.927062    0.55324435 -0.5888569   0.25844514  3.160447\n",
      " -0.4356788   1.4796567  -2.2074952  -0.16404074],准确率为:0.914509117603302\n",
      "网络训练运行时间是4541.2404153347015\n"
     ]
    }
   ],
   "source": [
    "#变量初始化\n",
    "init=tf.global_variables_initializer()\n",
    "\n",
    "#开启会话\n",
    "start=time.time()\n",
    "with tf.Session() as sess:\n",
    "    sess.run(init)\n",
    "    imge=minist.train.images[:]\n",
    "    lable=minist.train.labels[:]\n",
    "    print(\"训练之前，损失为：{}\".format(sess.run(error,feed_dict={x:imge,y_true:lable})))\n",
    "    #开始训练\n",
    "    for i in range(3001):\n",
    "        _,loss,accuracy_value=sess.run([optimizer,error,accuracy],feed_dict={x:imge,y_true:lable})\n",
    "        if i%100==0:\n",
    "            print(\"第{}次训练的损失为{},准确率为:{}\".format(i,loss,accuracy_value))    \n",
    "        if i==3000:\n",
    "            print(\"最终训练出来的w:\\n{}\\nb:{},准确率为:{}\".format(weight.eval(),bias.eval(),accuracy_value))\n",
    "\n",
    "end=time.time()\n",
    "print(\"网络训练运行时间是{}\".format(end-start))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
